// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#include <pollux/functions/prestosql/types/tdigest_type.h>
#include <pollux/functions/prestosql/types/tdigest_registration.h>
#include <pollux/functions/prestosql/types/tests/TypeTestBase.h>
#include <pollux/type/parser/type_parser.h>

namespace kumo::pollux::test {
namespace {

class TDigestTypeTest : public testing::Test, public TypeTestBase {
 public:
  TDigestTypeTest() {
    registerTDigestType();
  }
};

TEST_F(TDigestTypeTest, basic) {
  ASSERT_STREQ(TDIGEST(DOUBLE())->name(), "TDIGEST");
  ASSERT_STREQ(TDIGEST(DOUBLE())->kindName(), "VARBINARY");
  ASSERT_EQ(TDIGEST(DOUBLE())->parameters().size(), 1);
  ASSERT_EQ(TDIGEST(DOUBLE())->toString(), "TDIGEST(DOUBLE)");

  ASSERT_TRUE(hasType("TDIGEST"));
  ASSERT_EQ(*getType("TDIGEST", {TypeParameter(DOUBLE())}), *TDIGEST(DOUBLE()));
}

TEST_F(TDigestTypeTest, serde) {
  testTypeSerde(TDIGEST(DOUBLE()));
}

TEST_F(TDigestTypeTest, parse) {
  ASSERT_EQ(*parseType("tdigest(double)"), *TDIGEST(DOUBLE()));
}

} // namespace
} // namespace kumo::pollux::test
